package com.dev1.pack01web.websocket;

import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;


//ws://localhost:8080/project1/websocket/1001
@Component  //类似@Controller
@ServerEndpoint("/websocket/{username}")
public class HelloSocket {
    //@OnXxx    在Xxx这个行为发生的时候，执行方法
    @OnOpen
    public void onOpen(@PathParam("username") String username, Session session) {
        System.out.println("onOpen" +username);
    }
    @OnError
    public void onError(Session session, Throwable error) {
        System.out.println("onError");
    }
    @OnClose
    public void onClose() {
        System.out.println("onClose");
    }
    @OnMessage
    public void onMessage(String message, Session session) {
        System.out.println("onMessage "+message);
    }
}
